package com.sparrow.common.metric.domain;

import java.util.*;

public class PerfKey {
    private final String name;
    private final Map<String, String> tags;

    public PerfKey(String name, Map<String, String> tags) {
        this.name = name;
        this.tags = Collections.unmodifiableMap(new TreeMap<>(tags)); // 保证有序一致性
    }

    public String getName() {
        return name;
    }

    public Map<String, String> getTags() {
        return tags;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof PerfKey)) return false;
        PerfKey that = (PerfKey) o;
        return name.equals(that.name) && tags.equals(that.tags);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, tags);
    }

    @Override
    public String toString() {
        if (tags.isEmpty()) {
            return name;
        }
        return name + tags;
    }
}